package cn.duli.xianer.service.impl;

import cn.duli.xianer.dao.WantGoodsCollectionMapper;
import cn.duli.xianer.pojo.WantGoodsCollection;
import cn.duli.xianer.service.WantGoodsCollectionService;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WantGoodsCollectionServiceImpl implements WantGoodsCollectionService {

    @Resource
    private WantGoodsCollectionMapper wantGoodsCollectionMapper;

    @Override
    public void save(WantGoodsCollection wantGoodsCollection) {
        wantGoodsCollectionMapper.save(wantGoodsCollection);
    }

    @Override
    public WantGoodsCollection findById(Integer wgcId) {
        return wantGoodsCollectionMapper.findById(wgcId);
    }

    @Override
    public void deleteById(Integer wgcId) {
        wantGoodsCollectionMapper.deleteById(wgcId);
    }

    @Override
    public Page<WantGoodsCollection> findByUserId(Integer wgcUid) {
        return wantGoodsCollectionMapper.findByUserId(wgcUid);
    }

    @Override
    public WantGoodsCollection findByAllId(Integer wgcWgid, Integer wgcUid) {
        return wantGoodsCollectionMapper.findByAllId(wgcWgid, wgcUid);
    }

    @Override
    public boolean isCollection(Integer wgcWgid, Integer wgcUid) {
        // 查询数据库中want_goods_collection表里面是否有这条收藏信息
        WantGoodsCollection wantGoodsCollection = wantGoodsCollectionMapper.findByAllId(wgcWgid, wgcUid);
        return wantGoodsCollection == null?false:true;
    }

    @Override
    public Page<WantGoodsCollection> findAll() {
        return wantGoodsCollectionMapper.findAll();
    }
}
